<? 
session_start();
include ('../parametros/bd.php');
$conect = new conector_pg();
$conect-> conectar();
 
$sql="select * 
	  from libros l,
	  	   categorias c
	  where c.idcategoria = l.idcategoria 
	  order by autor"; 
// Ejecutas la consulta y guardas el resultado en una variable 
$result=$conect->consultar($sql);
if (!$result){
	echo 'error en la consulta'	;
	exit;
} 

$libro_datos=array();
$ind=0;		 
while ($lida= pg_fetch_array($result, null, PGSQL_ASSOC)){
	$libro_datos[$ind]=$lida;
	$ind = $ind + 1;
}		 
?>
<?php if (isset($_SESSION['logged_in'])) 
	   { 
	   	if ($_SESSION['admin'] == 1)
	   	{ 
?>
<html>
<head>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
<link href="../css/imageMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="XoR-main">
			<div class="XoR-sheet">
				<div class="XoR-sheet-tl"></div>
				<div class="XoR-sheet-tr"></div>
				<div class="XoR-sheet-bl"></div>
				<div class="XoR-sheet-br"></div>
				<div class="XoR-sheet-tc"></div>
				<div class="XoR-sheet-bc"></div>
				<div class="XoR-sheet-cl"></div>
				<div class="XoR-sheet-cr"></div>
				<div class="XoR-sheet-cc"></div>
				<div class="XoR-sheet-body">
					<div class="XoR-header">
						<div class="XoR-header-center">
							<div class="XoR-header-png"></div>
							<div class="XoR-header-jpeg"></div>
						</div>
						<div class="XoR-logo">
							<h1 id="name-text" class="XoR-logo-name"><a href="./index.html">Libreria TAI</a></h1>
							<h2 id="slogan-text" class="XoR-logo-text">Primera Libreria Online del Paraguay</h2>
						</div>
					</div>
<h1 id="tituloNaranja2">Consulta de libros</h1>
<table> 
  <tr>
    <th id="labelLogin">Autor</th>
    <th id="labelLogin">Titulo</th>
    <th id="labelLogin">Categoria</th>
    <th id="labelLogin">Precio</th>
    <th id="labelLogin">Formato Disponible</th>
    <th id="labelLogin">Acciones</th>
  </tr>

  	<? 
  	foreach ($libro_datos as $ind => $valor) {?>
  	<tr> 
		<td id="searchForm"><?echo $valor['autor']?> </td>
		<td id="searchForm"><?echo $valor['titulo']?> </td>
		<td id="searchForm"><?echo $valor['descripcion']?> </td>
		<td id="searchForm"><?echo $valor['precio']?> </td>
		<td id="searchForm"><?if ($valor['pdf']!=0)
								{
									echo "PDF ";
								};
							    if ($valor['mp3']!=0)
								{
									echo "MP3 ";
								};
								if ($valor['impreso']!=0)
								{
									echo "IMPRESO(".$valor['impreso'].")";
								};	
		
							?> 
		</td>
		<td>
		<? 
			$_SESSION['idlibro'] =$valor['idlibro'];
			$_SESSION['url2'] = ('edicionlibro.php'.'?id='.$_SESSION['idlibro']);
        ?>
			 <a id="submitLogin" href="<?php echo $_SESSION['url2']?>">Editar</a>
        </td>
	</tr>
	<?}?>	
</table>
<a id="submitLogin"  href="insertarlibros.php"> Nuevo libro </a>
<br>
<a id="labelLogin" href="indexadmin.php"> Regresar al listado </a>
<?php 
	   	}
?>
<a href="../login/logout.php?signature=<?php echo $_SESSION['signature']; ?>
">Logout</a><br /><?php } 
?>
<div class="cleared"></div>
					<div class="XoR-footer">
						<div class="XoR-footer-body">
							<div class="XoR-footer-text">
								<p>Copyright 2011, XoR Company. All Rights Reserved.</p>
							</div>
							<div class="cleared"></div>
						</div>
					</div>
					<div class="cleared"></div>
				</div>
			</div>
			<div class="cleared"></div>
			<p class="XoR-page-footer">Powered by <a href="http://xor.net/">XoR.org</a> </p>
		</div>
</body>
</html>
